package com.wanda.upload;

import java.io.IOException;
import java.io.OutputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import com.wanda.model.RoomPBUAPModel;

import java.io.*;

/**
 * @author lcr
 *
 * 毕业生基本生源信息导出Excel文件
 */
public class ExportRoom {

        /**
         * 学生生源信息的代码加上文字的双向导出
         * 
         * @param List
         *            <String> header excel文件的每一列的头信息
         * @param ResultSet
         *            rs 封装了数据库中所有的符合条件信息
         * @return
         * @throws SQLException
         *
         */

        public void exportExcel(List<String> header, ResultSet rs,
                        String sheetName, OutputStream output, String name)
                        throws SQLException {

                Integer count = 0;

                HSSFWorkbook wb = new HSSFWorkbook();

                HSSFSheet sheet1 = wb.createSheet("所选房间列表");// 创建工作表

                HSSFCellStyle cellstyle = wb.createCellStyle();// 单元格样式

                /*--------------------设置列头得样式表-------------*/
                HSSFFont font = wb.createFont();

                font.setBoldweight((short) 20);

                // font.setFontName("宋体");

                font.setFontHeightInPoints((short) 10);

                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

                /*---------------------------------------------------*/

                cellstyle.setFont(font);

                HSSFRow row = sheet1.createRow(0);// 创建工作表中的一行---------每一列的列头

                for (int i = 0; i < header.size(); i++) {

                        HSSFCell cell1 = row.createCell(i);

                        cell1.setCellStyle(cellstyle);// 设置单元格样式

                        cell1.setCellValue(header.get(i));

                        sheet1.setColumnWidth(i, (int) 7000);

                }

                while (rs.next()) {

                        count = count + 1;

                        row = sheet1.createRow(count);

                        for (int i = 0; i < header.size(); i++) {

                                row.createCell(i).setCellValue(rs.getString(i + 1));

                        }

                }

                try {

                        output.flush();

                        wb.write(output);

                        output.close();

                } catch (IOException e) {

                        e.printStackTrace();

                        System.out.println("Output   is   closed ");

                }

        }

        /**
         * @param header
         * @param studentlist
         * @param sheetName
         * @param output
         * @param name
         */

        public void exportExcel_Code(List<String> header,
                        List<RoomPBUAPModel>Myroomlist, String sheetName) {
                        OutputStream output = null;
                        try {
                            output = new FileOutputStream("d://myroom.xls");
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }

                HSSFWorkbook wb = new HSSFWorkbook();

                HSSFSheet sheet1 = wb.createSheet("所选房间信息列表");// 创建工作表

                HSSFCellStyle cellstyle = wb.createCellStyle();// 单元格样式

                /*--------------------设置列头得样式表-------------*/
                HSSFFont font = wb.createFont();

                font.setBoldweight((short) 20);

                // font.setFontName("宋体");

                font.setFontHeightInPoints((short) 10);

                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

                /*---------------------------------------------------*/

                cellstyle.setFont(font);

                HSSFRow row = sheet1.createRow(0);// 创建工作表中的一行---------每一列的列头

                for (int i = 0; i < header.size(); i++) {

                        HSSFCell cell1 = row.createCell(i);

                        cell1.setCellStyle(cellstyle);// 设置单元格样式

                        cell1.setCellValue(header.get(i));

                }

                if (Myroomlist.size() > 0) {

                        for (int j = 0; j < Myroomlist.size(); j++) {

                        	RoomPBUAPModel myroom = (RoomPBUAPModel)Myroomlist.get(j);

                                row = sheet1.createRow(j + 1);
                                 row.createCell(0).setCellValue(myroom.getProject_id());
                                 row.createCell(1).setCellValue(myroom.getRoom_code());
                                 row.createCell(2).setCellValue(myroom.getUnits());
                                 row.createCell(3).setCellValue(myroom.getInners());
                                 row.createCell(4).setCellValue(myroom.getOpening().getPrice_type());
                                 row.createCell(5).setCellValue(myroom.getUnit_price());
                                 row.createCell(6).setCellValue(myroom.getInner_price());
                                 row.createCell(7).setCellValue(myroom.getStandard_price());

                                
                        }

                }

                try {

                        output.flush();

                        wb.write(output);

                        output.close();

                } catch (IOException e) {

                        e.printStackTrace();

                        System.out.println("Output   is   closed ");

                }

        }

        /**
         * 导出问卷信息
         *
         * @param header
         * @param studentlist
         * @param sheetName
         * @param output
         * @param name
         */

}
